package com.mxy.myapplication2.kotlin

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.mxy.myapplication2.R

/**
 * Socket服务端消息列表适配器
 */
class AdapterForSocketServerInformationList constructor(context: Context, informations: ArrayList<String>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

    private var context: Context
    private var informations: ArrayList<String>
    private var layoutInflater: LayoutInflater

    init {
        this.context = context
        this.informations = informations
        this.layoutInflater = LayoutInflater.from(this.context)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        val myViewHolder = MyViewHolder(this.layoutInflater.inflate(R.layout.item_socket_informationlist, null, false))
        return myViewHolder
    }

    override fun getItemCount(): Int {
        return this.informations.size
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {

        holder as MyViewHolder
        holder.content.text = informations.get(position)

    }


    inner class MyViewHolder constructor(itemView: View) : RecyclerView.ViewHolder(itemView) {

        var content: TextView

        init {
            content = itemView.findViewById(R.id.content)
        }
    }
}